fix(types): zod example teaches the Zod 4 .issues accessor, and examples/ is type-checked (#2919) - #2939
Merged
Merged
Conversation
…amples/` is type-checked (#2919) `ZodError.errors` was removed in Zod 4 (the repo is on 4.4.3). `packages/types/examples/zod-validation-example.ts` read `.errors` in seven places, so every `console.error` printed `undefined` and the last one — `invalidButtonResult.error.errors.length` — threw `TypeError: Cannot read properties of undefined (reading 'length')`, killing the example before its summary. Same bug and same cause as the `objectui validate` fix in #2919. `src/zod/README.md` documented the same dead accessor plus a Zod 3 issue shape; both corrected against what 4.4.3 emits (`invalid_value` + `values`, and "Invalid option: expected one of ..."). The example was invisible to CI, so the swap alone would let this rot again. `packages/types` type-checks a project whose `include` is `["src/**/*"]`, so `examples/` sat outside it — the `"examples"` entry in `exclude` was belt-and-braces, and deleting it alone would have changed nothing. Examples cannot join that project either: it is the package build (`tsc` -> `dist`) with `rootDir: "./src"`, `composite` and `declaration`. Added an emit-free `tsconfig.examples.json` and chained it from `type-check`. The example now imports `../src/zod/index.zod` instead of `../dist/zod/index.zod.js`, matching its three sibling example files, so the check needs no prior build. Verified the gate has teeth: restoring `.errors` fails with seven `TS2339: Property 'errors' does not exist on type 'ZodError<...>'`. Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ZodError.errorswas removed in Zod 4; this repo is on zod 4.4.3.packages/types/examples/zod-validation-example.tsread
.errorsin seven places. Six printedundefined; the seventh —invalidButtonResult.error.errors.length— threw, killing the example before its summary.Confirmed empirically on 4.4.3 rather than assumed:
And on the file itself, before the fix:
After: it runs clean end-to-end and prints
Expected validation errors: 2.Same bug, same cause as the
objectui validatefix in #2919 / #2936, used as the reference.src/zod/README.mdcarried the same dead accessor plus a Zod 3 issue shape(
code: 'invalid_enum_value',"Invalid enum value. Expected …"). Both correctedagainst what 4.4.3 actually emits:
code: 'invalid_value'with avaluesarray and'Invalid option: expected one of …'.Decision 1 — swap and gate, because the swap alone would rot again
Not just
.errors->.issues. The file is invisible to CI, so nothing stops the next drift.One correction to the framing in the issue: removing
"examples"frompackages/types/tsconfig.json'sexcludewould have changed nothing. That project'sincludeis already["src/**/*"], so theexcludeentry is belt-and-braces. Examples also cannot simply join that project — it is the package build (tsc->dist) withrootDir: "./src",compositeanddeclaration, so example files are both outsiderootDirand would emit intodist.So: a separate emit-free
tsconfig.examples.jsonoverexamples/**/*.ts, chained from the package script:The example also now imports
../src/zod/index.zodinstead of../dist/zod/index.zod.js— matching its three sibling example files (dashboard.ts,login-form.ts,rest-data-source.ts, all on../src/index) — so the check needs no prior build.Verified the gate has teeth rather than trusting the green (the standard set by #2936): restoring
.errorsmakestsc -p tsconfig.examples.jsonfail with sevenDecision 2 — other
examples/dirs: one shares the exclusion, none share the riskGrepped
error.errorsrepo-wide over tracked files. Three hits beyond this file:packages/cli/src/commands/validate.ts:87main.packages/types/src/zod/README.md:246packages/data-objectstack/src/errors.test.ts:112BulkOperationError.errors, a custom class property, unrelated to Zod.On the directories themselves:
examples/*— not a gap. All four are real workspace packages;byo-backend-console,console-starterandschema-catalogeach already carry"type-check": "tsc --noEmit", soturbo run type-checkcovers them.hello-worldhas no build and no tsconfig and is the declaredNOT_COMPILEDexemption incheck-type-check-coverage.mjs, re-validated on every run.packages/plugin-charts/examples/chart-examples.ts— the only other package-internal examples dir, and it does share the exclusion (include: ["src"]). But it carries no imports at all — 54 lines of bare exported object literals — so there is no API surface to go stale. I deliberately did not add a tsconfig there: with nothing typed, the check would pass regardless of drift, and a gate that cannot fail is worse than an honest gap. Making it meaningful means typing those literals against the chart schemas, which is real work outside this fix.So the systemic hole is narrower than "examples are excluded": it is package-internal
examples/dirs inside a package whosetype-checkis scoped tosrc. That set is exactly two, and only one had teeth to gain.Verification
pnpm --filter @object-ui/types type-check— passes (both projects)node scripts/check-type-check-coverage.mjs—41/45, unchanged (no package count change)npx eslint packages/types— 0 errors (263 pre-existingno-explicit-anywarnings in untouchedsrc/)tsxNo runtime or published-type change —
examples/is not in the package'sfiles.🤖 Generated with Claude Code